/*
* (C) Copyright 2013 Philip Kirchhoff 
* 
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
* 
*-------------------------------------------------------------------------------
* This file is part of the DataLogger library by Philip Kirchhoff
* https://code.google.com/p/pk-data-logger/
* SVN: http://pk-data-logger.googlecode.com/svn/trunk
*-------------------------------------------------------------------------------
* Module    : DlDataChannel.cpp   
* Author    : Kirchhoff, Philip
* Date      : 01.04.2013
*-------------------------------------------------------------------------------
* Function definitions for class DlDataChannel
*   
*-------------------------------------------------------------------------------
* Change History:
* 01.04.2013  Kirchhoff 	Created
--------------------------------------------------------------------------------
*/

#include <iostream>
#include <stdexcept>

#include "DlDataChannel.h"

using namespace std;


/**************************************************************************//**
* @brief Constructs a channel object with number and ID
* @param channelNum Channel number
* @param channelId ID of the channel
******************************************************************************/
DlDataChannel::DlDataChannel(ChannelType type, unsigned int channelNum,
                             string channelId, string channelUnit,
                             string channelDescr)
    : mChannelType(type), mChannelId(channelId), mChannelUnit(channelUnit),
      mChannelDescr(channelDescr)
{
    if(channelNum > DL_MAX_CHAN_NUM)
    {
        std::string excStr(__PRETTY_FUNCTION__);
        excStr += ": Invalid channel number!";
        throw std::range_error(excStr);
    }
    mChannelNum = channelNum;
}

/**************************************************************************//**
* @brief Destructor
******************************************************************************/
DlDataChannel::~DlDataChannel()
{

}

/**************************************************************************//**
* @brief Returns the channel type as string
* @return Channel type string
******************************************************************************/
std::string DlDataChannel::channelTypeString()
{
    switch(mChannelType)
    {
    case TYPE_DOUBLE:
        return std::string("float64");
    case TYPE_FLOAT:
        return std::string("float32");
    case TYPE_BOOL:
        return std::string("bool");
    case TYPE_LONG:
        return std::string("int32");
    case TYPE_ULONG:
        return std::string("uint32");
    case TYPE_SHORT:
        return std::string("int16");
    case TYPE_USHORT:
        return std::string("uint16");
    case TYPE_STRING:
        return std::string("string");
    default :
        std::string excStr(__PRETTY_FUNCTION__);
        excStr += ": Invalid channel type!";
        throw std::range_error(excStr);
    }
}


